import { FrameTimer } from "../../../../com/gengine/core/frame/FrameTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
import { ObjectPool } from "../../../../com/gengine/utils/pools/ObjectPool";
import { _tempFilters } from "../../../../this/_tempFilters";
type int = number;
//class GlowFilterEffect
    
    export  class GlowFilterEffect
    {
        constructor()
        {
            
            this._targetDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._effectNum = 0;
            this._frame = new FrameTimer();
            this._frame.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: FrameTimer): void
        {
            var loc1=undefined;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=this._targetDic;
            for (loc1 in loc6) 
            {
                if (loc1 == "null") 
                {
                    continue;
                }
                loc2 = this._targetDic[loc1];
                if (loc2["repeat"] != 0) 
                {
                    if (loc2["count"] >= loc2["repeat"]) 
                    {
                        this.unRegist(loc1);
                        continue;
                    }
                }
                if (loc2.hasOwnProperty("filters")) 
                {
                    loc3 = loc2["filters"];
                    var loc7=0;
                    var loc8=loc3;
                    for(loc4 of loc8) 
                    {
                        if (loc4.blurX <= loc2["min"]) 
                        {
                            loc4.blurX = loc2["min"];
                            loc4.blurY = loc2["min"];
                            if (loc2["step"] < 0) 
                            {
                                loc2["step"] = loc2["step"] * -1;
                            }
                            loc2["count"] = loc2["count"] + 0.5;
                        }
                        else if (loc4.blurX >= loc2["max"]) 
                        {
                            loc4.blurX = loc2["max"];
                            loc4.blurY = loc2["max"];
                            if (loc2["step"] > 0) 
                            {
                                loc2["step"] = loc2["step"] * -1;
                            }
                            loc2["count"] = loc2["count"] + 0.5;
                        }
                        loc4.blurX = loc4.blurX + loc2["step"];
                        loc4.blurY = loc4.blurY + loc2["step"];
                    }
                }
                if (!(loc1 && !(loc1 == "null") && loc3)) 
                {
                    continue;
                }
                loc1.filters = loc3;
            }
            return;
        }

        public regist(arg1: Object /* flash.display.DisplayObject */, arg2: Array<any>, arg3: number=1, arg4: int=20, arg5: int=3, arg6: int=0): void
        {
            var loc1=null;
            var loc2=null;
            if (arg1 == null || arg2 == null) 
            {
                return;
            }
            if (this._targetDic[arg1] != null) 
            {
                this.disposeTarget(arg1);
                var loc3;
                var loc4=((loc3 = this)._effectNum - 1);
                loc3._effectNum = loc4;
            }
            this._tempFilters = [];
            loc3 = 0;
            loc4 = arg2;
            for(loc2 of loc4) 
            {
                (loc1 = ObjectPool.getObject(flash.filters.GlowFilter)).color = loc2.color;
                loc1.alpha = loc2.alpha;
                loc1.blurX = loc2.blurX;
                loc1.blurY = loc2.blurY;
                loc1.strength = loc2.strength;
                loc1.quality = loc2.quality;
                loc1.inner = loc2.inner;
                loc1.knockout = loc2.knockout;
                this._tempFilters.push(loc1);
            }
            arg2.splice();
            this._targetDic[arg1] = {"filters": _tempFilters, "step": arg3, "max": arg4, "min": arg5, "repeat": arg6, "count": 0};
            loc4 = ((loc3 = this)._effectNum + 1);
            loc3._effectNum = loc4;
            if (!this._frame.running) 
            {
                this._frame.start();
            }
            return;
        }

        public getFilters(arg1: Object /* flash.display.DisplayObject */): Array<any>
        {
            if (this._targetDic[arg1] != null) 
            {
                return this._targetDic[arg1]["filters"];
            }
            return null;
        }

        public unRegist(arg1: Object /* flash.display.DisplayObject */): void
        {
            if (this._targetDic[arg1] == null) 
            {
                return;
            }
            else 
            {
                this.disposeTarget(arg1);
                var loc1;
                var loc2=((loc1 = this)._effectNum - 1);
                loc1._effectNum = loc2;
            }
            if (this._effectNum <= 0) 
            {
                if (this._frame.running) 
                {
                    this._frame.stop();
                }
            }
            return;
        }

        /* internal  */disposeTarget(arg1: Object /* flash.display.DisplayObject */): void
        {
            var loc2=null;
            var loc3=null;
            var loc1=this._targetDic[arg1];
            if (loc1 && loc1.hasOwnProperty("filters")) 
            {
                loc2 = loc1["filters"];
                var loc4=0;
                var loc5=loc2;
                for(loc3 of loc5) 
                {
                    ObjectPool.disposeObject(loc3, flash.filters.GlowFilter);
                }
            }
            delete this._targetDic[arg1];
            arg1.filters = null;
            return;
        }

        public unRegistAll(): void
        {
            var loc1=undefined;
            var loc2=0;
            var loc3=this._targetDic;
            for (loc1 in loc3) 
            {
                this.disposeTarget(loc1 as Object /* flash.display.DisplayObject */);
            }
            this._effectNum = 0;
            if (this._frame.running) 
            {
                this._frame.stop();
            }
            return;
        }

        /* internal */ /* var */_targetDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_frame: FrameTimer;

        /* internal */ /* var */_effectNum: int;

        /* internal */ /* var */_tempFilters: Array<any>;
    }
